using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[RequireComponent(typeof(InventoryItem))]
public class InventoryGridInteract : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    public InventoryItem inventoryItem;
    public void OnPointerExit(PointerEventData eventData)
    {
        inventoryItem.canShowDetail = false;
        inventoryItem = null;

        GameObject allText = GameObject.FindGameObjectWithTag("gridText");
        Vector2 mousePostion = Input.mousePosition;
        mousePostion = mousePostion - new Vector2(-1000, 1000);
        allText.GetComponent<RectTransform>().position = mousePostion;

        Text[] text = allText.GetComponentsInChildren<Text>();

        foreach (Text content in text)
        {
            if (content.name == "productName")
            {
                content.text = null;
            }
            if (content.name == "productDetail")
            {
                content.text = null;
            }
            if (content.name == "productPrice")
            {
                content.text = null;
            }
        }

    }

    void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
    {
        inventoryItem = GetComponent<InventoryItem>();
        inventoryItem.canShowDetail = true;

        //string name = inventoryItem.itemData.productName;
        //int price = inventoryItem.itemData.price;
        //string describe = inventoryItem.itemData.describe;

        //GameObject allText = GameObject.FindGameObjectWithTag("gridText");
        //Vector2 mousePostion = Input.mousePosition;
        //mousePostion = mousePostion - new Vector2(-60, 50);
        //allText.GetComponent<RectTransform>().position = mousePostion;

        //Text[] text = allText.GetComponentsInChildren<Text>();
        //foreach (Text content in text)
        //{
        //    if (content.name == "productName")
        //    {
        //        content.text = name;
        //    }
        //    if (content.name == "productDetail")
        //    {
        //        content.text = describe;
        //    }
        //    if (content.name == "productPrice")
        //    {
        //        content.text = price + "";
        //    }
        //}
    }
    
}
